<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Privacy.php 2010-08-31 16:05 idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Page
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Page_Form_Privacy extends Engine_Form
{
	protected $_parent_type;
  protected $_parent_id;
  
  public function setParent_type($value)
  { 
    $this->_parent_type = $value;
  }

  public function setParent_id($value)
  {
    $this->_parent_id = $value;
  }
  
	public function init()
  {
  	$user = Engine_Api::_()->user()->getViewer();
  	
  	$this
      ->setTitle('')
      ->setMethod('post')
      ->setAttrib('id', 'page_edit_form_privacy')
      ->setAttrib('class', 'page_edit_form hidden');
      
    $this->addElement('Hidden', 'edit', array('value' => 'privacy'));
      
  	$this->addElement('Radio', 'search', array(
  		'label' => 'Search Privacy',
      'description' => 'Include this page in search results?',
      'value' => 1,
  		'multiOptions' => array(
  				1 => 'Yes, include in search results.',
  				0 => 'No, hide from search results.'
  		)
    ));
    
    $availableLabels = array(
      'everyone' => 'Everyone',
      'registered' => 'Registered Members',
      'likes' => 'Likes, Admins and Owner',
      'team' => 'Admins and Owner Only'
    );
    
    $view_options = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('page', $user, 'auth_view');
    $view_options = array_intersect_key($availableLabels, array_flip($view_options));

    $comment_options = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('page', $user, 'auth_comment');
    $comment_options = array_intersect_key($availableLabels, array_flip($comment_options));

    $posting_options = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('page', $user, 'auth_posting');
    $posting_options = array_intersect_key($availableLabels, array_flip($posting_options));
    
  	if (!empty($view_options)) {
      $this->addElement('Radio', 'auth_view', array(
        'label' => 'View Privacy',
        'description' => 'Who can see this page?',
        'multiOptions' => $view_options,
        'value' => key($view_options),
      ));
    }
    
  	if (!empty($posting_options)){
      $this->addElement('Radio', 'auth_posting', array(
        'label' => 'Posting Privacy',
        'description' => 'Who can post photos, videos, blogs and events?',
        'multiOptions' => $posting_options,
        'value' => key($posting_options),
      ));
    }

    if (!empty($comment_options)){
      $this->addElement('Radio', 'auth_comment', array(
        'label' => 'Comment Privacy',
        'description' => 'Who can comment photos, videos, blogs and events?',
        'multiOptions' => $comment_options,
        'value' => key($comment_options),
      ));
    }
    
    // Buttons
    $this->addElement('Button', 'submit', array(
      'label' => 'Save',
      'type' => 'submit',
      'ignore' => true,
      'decorators' => array('ViewHelper')
    ));
    
  }
}